package com.example.isoftservice.service.impl;

import com.example.isoftservice.mapper.InstitutionBigCategoryMapper;
import com.example.isoftservice.pojos.Category;
import com.example.isoftservice.pojos.InstitutionBigCategory;
import com.example.isoftservice.service.InstitutionBigCategoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class InstitutionBigCategoryServiceImpl implements InstitutionBigCategoryService {

    @Resource
    private InstitutionBigCategoryMapper institutionBigCategoryMapper;
    @Override
    @Cacheable(cacheNames ="instiutionbig",key="#pageNo+pageSize")
    public Map<String, Object> searchBigCategoryList(Integer pageNo, Integer pageSize) {
        Map<String, Object> map = new HashMap<>();
        PageHelper.startPage(pageNo,pageSize);
        List<Map<String,Object>> resultList = institutionBigCategoryMapper.selectBigCategoryList();
        PageInfo<Map<String,Object>> info = new PageInfo(resultList);
        map.put("total",info.getTotal());
        map.put("rows",info.getList());
        return map;
    }

    @Override
    @Cacheable(cacheNames ="instiutionbig",key="#institutionBigCategoryId")
    public InstitutionBigCategory searchBigCategoryById(Integer institutionBigCategoryId) {
        return institutionBigCategoryMapper.selectBigCategoryById(institutionBigCategoryId);
    }

    @Override
    @Cacheable(cacheNames ="instiutionbig",key="#institutionBigCategoryId+pageNo+pageSize")
    public Map<String, Object> searchBelong(Integer institutionBigCategoryId,Integer pageNo, Integer pageSize) {
        Map<String, Object> map = new HashMap<>();
        PageHelper.startPage(pageNo,pageSize);
        List<Map<String,Object>> resultList = institutionBigCategoryMapper.selectBelong(institutionBigCategoryId);
        PageInfo<Map<String,Object>> info = new PageInfo(resultList);
        map.put("total",info.getTotal());
        map.put("rows",info.getList());
        return map;
    }

    @Override
    @CacheEvict(cacheNames = "instiutionbig" ,allEntries = true)
    public Boolean addBigCategory(InstitutionBigCategory institutionBigCategory) {
        return institutionBigCategoryMapper.insertBigCategory(institutionBigCategory) == 1 ? true : false;
    }

    @Override
    @CacheEvict(cacheNames = "instiutionbig" ,allEntries = true)
    public Boolean removeBigCategoryByIds(Integer[] ids) {
        return institutionBigCategoryMapper.deleteBigCategoryByIds(ids) >= 1 ? true : false;
    }

    @Override
    @CacheEvict(cacheNames = "instiutionbig" ,allEntries = true)
    public Boolean modifyBigCategoryById(InstitutionBigCategory institutionBigCategory) {
        return institutionBigCategoryMapper.updateBigCategoryById(institutionBigCategory) == 1 ? true : false;
    }
}
